n = int(input())
A = {}
for i in range(n):
    s = input()
    b = s.split()[2:]
    a = s.split()[0]
    for e in range(len(b)-1):
        b[e] = b[e][:-1]
    for e in range(len(b)):
        if b[e] in A:
            A[b[e]] = A[b[e]] + ", " + a
        else:
            A[b[e]] = a
print(len(A))
c = []
for i in A:
    c.append(i + " - " + A[i])
c.sort()
for i in range(len(A)):
    print(c[i])